// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "ProceduralSectorComponent.h"
#include "Components/ActorComponent.h"
#include "VFXChartComponent.generated.h"

USTRUCT(BlueprintType)
struct FDataValue
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	int Index;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FString Name;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float Value;
};

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class VISUALCHARTFX_API UVFXChartComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UVFXChartComponent();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;
	virtual void OnRegister() override;
	virtual void OnUnregister() override;

protected:
#if WITH_EDITOR
	virtual void PreEditChange(FProperty* PropertyThatWillChange) override;
#endif // WITH_EDITOR
public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

	UFUNCTION(BlueprintCallable)
	void SetValues(TArray<FDataValue> ValuesArray);

	UFUNCTION(BlueprintCallable)
	void BuildBarChart();

	UFUNCTION(BlueprintCallable)
	void BuildPieChart();

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="VisualFXChart")
	TObjectPtr<UMaterialInterface> MaterialInterface;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="VisualFXChart")
	TObjectPtr<UMaterialInterface> TextMaterial;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="VisualFXChart")
	TObjectPtr<UDataTable> ChartDataTable;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="VisualFXChart")
	TObjectPtr<UDataTable> PaletteTable;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="VisualFXChart")
	float CenterOffset;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="VisualFXChart")
	float LabelRadiusPos;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="VisualFXChart")
	float Radius;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="VisualFXChart")
	float Height;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="VisualFXChart")
	float Bevel;

private:	
	bool NeedRebuild;
	TArray<FDataValue> Data;
	TArray<TObjectPtr<USceneComponent>> ProcedrualMeshComponents;
};
